package com.bawei.hgshop.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import com.bawei.hgshop.entity.OrderDetail;
import com.bawei.hgshop.entity.Orders;

public interface OrderMapper {

	@Insert("insert into hg_orders(uid,sumtotal,address,create_time) values(#{uid},#{sumtotal},#{address},now())")
	@Options(useGeneratedKeys = true,keyColumn = "oid",keyProperty = "oid")
	void add(Orders orders);

	@Insert("insert into hg_orderdetail(skuid,total,oid,pnum) values(#{sku.id},#{total},#{oid},#{pnum})")
	void addDetail(OrderDetail orderDetail);
 
	// 减少库存 
	@Update("update hg_sku set stock_count=stock_count-#{pnum} where id=#{id}")
	void decreaseStock(@Param("id")int id, @Param("pnum") int pnum);

}
